const AWS = require('aws-sdk');
AWS.config.update({region:'us-east-2'});
const cognitoidentityserviceprovider = new AWS.CognitoIdentityServiceProvider();
// https://docs.aws.amazon.com/cognito-user-identity-pools/latest/APIReference/API_AdminConfirmSignUp.html
const d = {};

/* params example
{
   "ClientMetadata": {
      "string" : "string"
   },
   "DesiredDeliveryMediums": [ "string" ],
   "ForceAliasCreation": boolean,
   "MessageAction": "string",
   "TemporaryPassword": "string",
   "UserAttributes": [
      {
         "Name": "string",
         "Value": "string"
      }
   ],
   "Username": "string",
   "UserPoolId": "string",
   "ValidationData": [
      {
         "Name": "string",
         "Value": "string"
      }
   ]
}
 */
d.createUser = (params) => new Promise((resolve, reject) => {
  cognitoidentityserviceprovider.adminCreateUser(params, function(err, data) {
    if (err) {
      reject(err);
      console.log(err, err.stack);
    } // an error occurred
    else {
      resolve(data);
      // console.log(data);
    }// successful response
  });
});

/* params example
{
   "ClientMetadata": {
      "string" : "string"
   },
   "Username": "string",
   "UserPoolId": "string"
}
 */
d.confirmUser = (params) => new Promise((resolve, reject) => {
  cognitoidentityserviceprovider.adminConfirmSignUp(params, function(err, data){
    if (err) {
      reject(err);
      console.log(err, err.stack);
    } // an error occurred
    else {
      resolve(data);
      // console.log(data);
    }// successful response
  });
});

/* params example
{
   "ClientMetadata": {
      "string" : "string"
   },
   "UserAttributes": [
      {
         "Name": "string",
         "Value": "string"
      }
   ],
   "Username": "string",
   "UserPoolId": "string"
}
 */
d.updateUser = (params) => new Promise((resolve, reject) => {
  cognitoidentityserviceprovider.adminUpdateUserAttributes(params, function(err, data){
    if (err) {
      reject(err);
      console.log(err, err.stack);
    } // an error occurred
    else {
      resolve(data);
      // console.log(data);
    }// successful response
  });
});

/* params example
{
   "AccessToken": "string",
   "PreviousPassword": "string",
   "ProposedPassword": "string"
}
 */
d.changePassword = (params) => new Promise((resolve, reject) => {
  cognitoidentityserviceprovider.changePassword(params, function(err, data){
    if (err) {
      reject(err);
      console.log(err, err.stack);
    } // an error occurred
    else {
      resolve(data);
      // console.log(data);
    }// successful response
  });
});

module.exports = d;